Fix[mqb]: improve non-printable handling in negotiation/session logs - #1675
Conversation
|
|
||
| /// Return `true` if every character in the specified string `str` is | ||
| /// printable, and `false` otherwise. An empty string is printable. | ||
| static bool isPrintable(const bslstl::StringRef& str); |
There was a problem hiding this comment.
I thought we were going to use bsl::string_view from now on.
Worth changing in the future
There was a problem hiding this comment.
All methods in this class using StringRef, I'll save that migration for another PR.
| template <class TYPE> | ||
| bsl::string logSafe(const TYPE& obj) | ||
| { | ||
| bmqu::MemOutStream os; |
There was a problem hiding this comment.
Might use local sequential allocator to ensure no heap allocations in most cases
There was a problem hiding this comment.
I followed convention in this file, most places don't use it for logging.
| template <class TYPE> | ||
| bool isPrintable(const TYPE& obj) | ||
| { | ||
| bmqu::MemOutStream os; |
There was a problem hiding this comment.
Local sequential allocator might be used here too
|
|
||
| // Detect non-printable characters in negotiation messages. | ||
| // TODO: fail negotiation if message contains non-printable characters | ||
| BSLS_REVIEW_OPT(isPrintable(negotiationContext->negotiationMessage())); |
There was a problem hiding this comment.
If negotiationMessage is printable, it automatically means that its client identity is also printable. This means that the following safe logs are not needed: logSafe(clientIdentity)
There was a problem hiding this comment.
We don't know if it's printable, that's why we have to sanitize until we reach the end goal of rejecting negotiation if not printable.
628056d to
9a8a574
Compare
Restrict negotiation messages (and derived fields) to printable characters in logs. Additionally, add a BSLS_REVIEW check for negotiation messages containing non-printable characters in anticipation of enforcing that string fields are limited to printable ASCII characters. Signed-off-by: Christopher Beard <cbeard9@bloomberg.net>
9a8a574 to
54316eb
Compare
Restrict negotiation messages (and derived fields) to printable characters in logs.
Additionally, add a BSLS_REVIEW check for negotiation messages containing non-printable characters in anticipation of enforcing that string fields are limited to printable ASCII characters.